<?php
declare (strict_types=1);

namespace app\controller;

use EasyWeChat\Factory;

class Wechat
{
    private $wechatApp;

    /**
     * @return mixed
     */
    public function getWechatApp()
    {
        return $this->wechatApp;
    }

    /**
     * @param mixed $wechatApp
     */
    public function setWechatApp($wechatApp): void
    {
        $this->wechatApp = $wechatApp;
    }

    public function __construct()
    {
        $this->setWechatApp($this->getFactoryObject());
    }

    /**
     * ### 获取EW的app对象
     * @return \EasyWeChat\Work\Application
     */
    public function getFactoryObject()
    {
        $config = [
            'corp_id' => 'ww229aacb70b341ff3',

            'agent_id' => 1000002, // 如果有 agend_id 则填写
            'secret' => '0IzOSc55L5E8BebMABcsRsOjFF9jyyHF3moOhqQOUKI',

            // 指定 API 调用返回结果的类型：array(default)/collection/object/raw/自定义类名
            'response_type' => 'array',

            'log' => [
                'level' => 'debug',
                'file' => public_path() . '/wechat/wechat.log',
            ],
        ];

        $app = Factory::work($config);
        return $app;
    }
}
